package com.sky.com.sky.web.admin;


import com.sky.result.Result;
import com.sky.service.WorkspaceService;
import com.sky.vo.BusinessDataVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import com.sky.websocket.WebSocketServer;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/admin/workspace")
@RequiredArgsConstructor
public class WorkSpaceController {
    @Autowired
     WorkspaceService workspaceService;

    @Autowired
    WebSocketServer webSocketServer;



    /**
     * 工作台今日数据查询
     * @return
     * **/
    @GetMapping("/businessData")
    public Result<BusinessDataVO> businessData(){
//        // 1.获取当天时间
//        LocalDate currentDate = LocalDate.now();
//        // 2.调用service查询
//        BusinessDataVO businessDataVO= workspaceService.getBusinessData2(currentDate);
//        // 3.返回VO
//        return Result.success(businessDataVO);
        LocalDate begin= LocalDate.now();
        LocalDate end = LocalDate.now();
        BusinessDataVO businessDataVO = workspaceService.getBusinessData1(begin, end);
        return Result.success(businessDataVO);
    }


    /**
     * 查询订单管理数据
     * @return
     * **/
    @GetMapping("/overviewOrders")
    public Result getOverviewOrders(){
        //1. 获取当天时间
        LocalDate currentDate = LocalDate.now();
        //2.调用service查询
        OrderOverViewVO vo = workspaceService.getOverviewOrders(currentDate);
        //3. 返回vo
        return Result.success(vo);
    }



    /**
     * 查询菜品总览
     * @return
     * **/
    @GetMapping("/overviewDishes")
    public Result<DishOverViewVO> dishOverVie(){
        return Result.success(workspaceService.getDishOverView());
    }



    /*
    * 查询套餐总览
    * @return
    * */
    @GetMapping("/overviewSetmeals")
    public Result<SetmealOverViewVO> setmealOverView(){
        return Result.success(workspaceService.getSetmealOverView());
    }


    //给指定客户端发送信息
    @GetMapping("/socket/push/{cid}")
    public void pushMessage(@PathVariable("cid") String cid,String message){
        webSocketServer.onMessage(message,cid);
    }

    //群发消息接口
    @GetMapping("/socket/pushAll")
    public String pushAll(String msg){
        webSocketServer.sendToAllClient(msg);
        return "ok";
    }


}
